//
//  ZallBaseCollectionViewCell.m
//  ZallDemo
//
//  Created by so on 16/6/16.
//  Copyright © 2016年 so. All rights reserved.
//

#import "ZallBaseCollectionViewCell.h"

@implementation ZallBaseCollectionViewCell
@synthesize gap = _gap;
@synthesize contentInsets = _contentInsets;
@synthesize borderView = _borderView;

#pragma mark - life cycle
- (instancetype)init {
    return ([self initWithFrame:CGRectZero]);
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        _gap = CGSizeZero;
        _contentInsets = UIEdgeInsetsZero;
    }
    return (self);
}
#pragma mark -

#pragma mark - override
- (void)layoutSubviews {
    [super layoutSubviews];
    if(_borderView) {
        self.borderView.frame = self.bounds;
    }
}

- (void)prepareForReuse {
    [super prepareForReuse];
    if(_borderView) {
        self.borderView.borderStyle = ZallBorderLineNone;
        [self.borderView setNeedsDisplay];
    }
}
#pragma mark -

#pragma mark - setter
- (void)setGap:(CGSize)gap {
    [self willChangeValueForKey:@"gap"];
    _gap = gap;
    [self didChangeValueForKey:@"gap"];
    [self setNeedsLayout];
}

- (void)setContentInsets:(UIEdgeInsets)contentInsets {
    [self willChangeValueForKey:@"contentInsets"];
    _contentInsets = contentInsets;
    [self didChangeValueForKey:@"contentInsets"];
    [self setNeedsLayout];
}
#pragma mark -

#pragma mark - getter
- (ZallBorderView *)borderView {
    if(!_borderView) {
        _borderView = [[ZallBorderView alloc] initWithFrame:self.bounds];
        _borderView.backgroundColor = [UIColor clearColor];
        [self insertSubview:_borderView atIndex:999];
    }
    return (_borderView);
}
#pragma mark -

@end
